import { type Directive } from 'vue'
import { usePermissionStore } from '@/stores/modules/permission'

export const permission: Directive = {
  mounted(el: HTMLElement, binding) {
    const permissionStore = usePermissionStore()
    const { value } = binding
    
    if (value && !permissionStore.hasPermission(value)) {
      el.parentNode?.removeChild(el)
    }
  }
}